diff --git a/includes/functions.php b/includes/functions.php index ba6c48a..7cb84be 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,87 +1,113 @@ . */ /** * It does what it's written. * * @param float $latitude1 * @param float $longitude1 * @param float $latitude2 * @param float $longitude2 * @return float Meters */ function get_distance_between_coordinates($latitude1, $longitude1, $latitude2, $longitude2) { $theta = $longitude1 - $longitude2; $distance = sin(deg2rad($latitude1)) * sin(deg2rad($latitude2)) + ( cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)) ); $distance = acos($distance); $distance = rad2deg($distance) * 60 * 1.1515; $distance = $distance * 1609.344; // To meters return $distance; } function get_in_touch($url, $who) { return HTML::a($url, mdi_icon('perm_contact_calendar') . _("Entra in contatto"), sprintf( _("Mettiti in contatto con %s"), $who ), 'waves-effect waves-teal btn'); } function legal_notes($url, $license, $project) { return HTML::a($url, $license, sprintf( _("Informazioni legali su %s"), $project ) ); } /** * Material Design Icon */ function mdi_icon($uid, $class = 'left') { return "$uid"; } /** * Run GNU Gettext */ function gettext_rocks($lang = 'it_IT', $domain = 'fuel.reyboz.it', $folder = 'l10n', $encoding = 'UTF-8') { putenv("LANG=$lang.$encoding"); setlocale(LC_MESSAGES, "$lang.$encoding"); bindtextdomain($domain, $folder); textdomain($domain); bind_textdomain_codeset($domain, $encoding); } /** * Get the last update price. * * Has a cache. * * @param string $format DateTime format. * @return string Formatted date. */ function last_price_date($format = 'd/m/Y H:i') { static $lastdate = null; if($lastdate === null) { $lastdate = query_value( "SELECT MAX(price_date) AS lastdate FROM {$GLOBALS[T]('price')}", 'lastdate' ); } $d = DateTime::createFromFormat('Y-m-d H:i:s', $lastdate); return $d->format($format); } + +/** + * Get either a Gravatar URL or complete image tag for a specified email address. + * + * @param string $email The email address + * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] + * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] + * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] + * @param boole $img True to return a complete IMG tag False for just the URL + * @param array $atts Optional, additional key/value attributes to include in the IMG tag + * @return String containing either just a URL or a complete image tag + * @source http://gravatar.com/site/implement/images/php/ + */ +function get_gravatar($email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) { + $url = '//www.gravatar.com/avatar/'; + $url .= md5( strtolower( trim( $email ) ) ); + $url .= "?s=$s&d=$d&r=$r"; + if($img) { + $url = ' $val) { + $url .= ' ' . $key . '="' . $val . '"'; + } + $url .= ' />'; + } + return $url; +}